<?php

class TypeattrModel extends Model{
	
	public $table = 'typeattr';
	//验证规则
	public $validate = array(
		array('tname',0,'属性名称不能为空',2,3),
		array('attrvalue',0,'属性值不能为空',2,3)
	
	);
	//添加属性
	public function add_attrlist(){
		
		if(!$this->create()) return false;
		$tname = Q('post.tname');
		$attrvalue = Q('post.attrvalue');
		$attrtype = Q('post.attrtype');
//		p(Q('post.'));
		$attrdata = array(
			'tname'     => $tname,
			'attrvalue' => $attrvalue,
			'attrtype'  => $attrtype
		);
		
		//判断类型是否重名
		if($this->get_one_attr(array('tname'=>$tname))){
			$this->error = $tname . '属性已经存在';
			return false;
		}
		
		return $this->add($attrdata);
	}
	
	
	//获取所有属性数据
	public function get_all_attr($where=NULL){
		return $this->where($where)->all();		
	}
	//获取一条属性
	public function get_one_attr($where=NULL,$field=NULL){
		return $this->where($where)->field($field)->find();
	}
	
	//修改
	public function update_attr($where=Null){
		return $this->where($where)->save();
	}
	
	public function del_attr($where){
		return $this->where($where)->delete();
	}
	
	
	
		
}//end
